local fn = vim.fn

-- 自动安装pakcer
local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
  PACKER_BOOTSTRAP = fn.system {
    "git",
    "clone",
    "--depth",
    "1",
    "https://github.com/wbthomason/packer.nvim",
    install_path,
  }
  print "Installing packer..."
  vim.cmd [[packadd packer.nvim]]
end

-- 未安装时退出,避免出错
local status_ok, packer = pcall(require, "packer")
if not status_ok then
  return
end

-- 初始化配置
packer.init {
  git = {
    cmd = "git",
    subcommands = {
      install = 'clone --depth 1 --progress'
    },
  },
}
-- local packer_root =fn.stdpath('data')..'/site/pack'
-- packer.init {
--   package_root = package_root,
--   git = { clone_timeout = 120 },
--   display = {
--     open_fn = function ()
--       return require('packer.util').float {border="single"}
--     end,
--     prompt_border = "single",
--   },
--   profile = {
--     enable = true,
--     threshold = 1,
--   },
--   auto_clean = true,
--   compile_on_sync = true,
-- }

return packer.startup(function(use)
  -- 安装管理插件
  use "wbthomason/packer.nvim"

  -- 插件依赖
  use "nvim-lua/popup.nvim"
  use "nvim-lua/plenary.nvim"

  -- 图标
  use "kyazdani42/nvim-web-devicons"

  -- 消息通知插件
  use "rcarriga/nvim-notify"

  -- telescope
  use {
    "nvim-telescope/telescope.nvim",
    tag = '0.1.0',
  }
  use {
    "nvim-telescope/telescope-fzf-native.nvim",
    run = "make",
  }
  use "ahmedkhalf/project.nvim"

  -- Treesittetr
  use {
    "nvim-treesitter/nvim-treesitter",
  }
  use {
    "nvim-treesitter/nvim-treesitter-textobjects",
  }
  use "romgrk/nvim-treesitter-context" -- show class/function at the top
  use "andymass/vim-matchup"

    -- LSP
  use "neovim/nvim-lspconfig"
  use "williamboman/nvim-lsp-installer"
  use "kosayoda/nvim-lightbulb"
  use "ray-x/lsp_signature.nvim"
  use "windwp/nvim-autopairs"

  -- cmp
  use "hrsh7th/nvim-cmp"
  use "hrsh7th/cmp-buffer"
  use "hrsh7th/cmp-path"
  use "hrsh7th/cmp-cmdline"
  use "saadparwaiz1/cmp_luasnip"
  use "hrsh7th/cmp-nvim-lsp"
  use "hrsh7th/cmp-nvim-lua"
  use "ray-x/cmp-treesitter"

  -- snippets
  use "L3MON4D3/LuaSnip"

  -- 注释
  use "terrortylor/nvim-comment"

  -- ui
  use {
    "catppuccin/nvim",
    as = "catppuccin"
  }
  use "RRethy/vim-illuminate" -- 突出显示
  use "nvim-lualine/lualine.nvim" -- 状态栏
  use "akinsho/bufferline.nvim" -- tab栏
  use "kyazdani42/nvim-tree.lua" -- 文件浏览器
  use "j-hui/fidget.nvim" -- lsp进度
  use "goolord/alpha-nvim" -- 起始页

  -- 片段运行(window下不支持)
  -- use { 'michaelb/sniprun', run = 'bash ./install.sh' }

  -- Git
  use "lewis6991/gitsigns.nvim"
  use "sindrets/diffview.nvim"

  -- trouble
  use "folke/trouble.nvim"
  use "folke/todo-comments.nvim"

  -- display
  use "folke/which-key.nvim"

  -- 自动保存
  use "Pocco81/AutoSave.nvim"

  -- 自动载入缓冲区的修改
  use "djoshea/vim-autoread"

  -- 代码相关
  use "ldelossa/litee.nvim"
  use "ldelossa/litee-calltree.nvim"
  use "ldelossa/litee-symboltree.nvim"

  -- debug
  use "mfussenegger/nvim-dap"
  use "rcarriga/nvim-dap-ui"
  use 'mfussenegger/nvim-dap-python'

  if PACKER_BOOTSTRAP then
    packer.sync()
  end
end)
